#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project : chat_model 
# @File    : vector_store_logic.py
# @IDE     : PyCharm 
# @Author  :ZH
# @Time    : 2025/1/10 11:12

__all__ = ['vector_store_logic']

from tortoise.expressions import Q

from apps import cruds
from apps.api.v1.vector_store_api.schema import VectorStoreListRequests


class VectorStoreLogic:
    def __init__(self):
        self.crud = cruds.vector_store_crud

    async def vector_store_list(self, query: VectorStoreListRequests):
        skip = (query.page - 1) * query.limit
        query_sql = self.crud.model.filter(is_delete=False)
        count_ = await query_sql.count()
        if count_:
            data = query_sql.order_by('-id').offset(skip).limit(query.limit).all()
        else:
            data = []
        return count_, data

    async def vector_store_object(self, vector_store_id: int):
        return await self.crud.get_one(
            id=vector_store_id, is_delete=False
        )


vector_store_logic = VectorStoreLogic()
